/**
 * Created by henian.xu on 2018/11/5.
 *
 */

const Controller = require('egg').Controller;

class HomeController extends Controller {
    async index() {
        const ctx = this.ctx;
        console.log('HomeController', ctx.status, ctx.method, ctx.path);
        const region = await ctx.service.region.getChild();
        ctx.res.renderData = { renderData: 'vue', region };
        await new Promise(resolve => {
            ctx.app.nuxt.render(ctx.req, ctx.res, () => {
                console.log('HomeController Render error');
                // nuxt.render passes a rejected promise into callback on error.
                // promise.then(resolve).catch(reject)
                resolve();
            });
        });
    }
}

module.exports = HomeController;
